package com.atguigu.spzx.cart.controller;

import com.atguigu.spzx.cart.service.CartService;
import com.atguigu.spzx.model.entity.h5.CartInfo;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "购物车管理")
@RestController
@RequestMapping("/api/order/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    @Operation(summary = "加入购物车")
    @GetMapping("/auth/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable Long skuId,@PathVariable Integer skuNum){

        cartService.addToCart(skuId,skuNum);
        return Result.ok(null);
    }

    @Operation(summary = "购物车")
    @GetMapping("/auth/cartList")
    public Result<List<CartInfo>> cartList(){
        List<CartInfo>cartInfoList=cartService.cartList();
        System.out.println("查询购物车");
        return Result.ok(cartInfoList);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/auth/deleteCart/{skuId}")
    public Result deleteCart(@PathVariable Long skuId){
        cartService.deleteCart(skuId);
        return Result.ok(null);
    }

    @Operation(summary = "更新选中状态")
    @GetMapping("/auth/checkCart/{skuId}/{isChecked}")
    public Result checkCart(@PathVariable("skuId") Long skuId,@PathVariable("isChecked") Integer isChecked){
        cartService.checkCart(skuId,isChecked);
        return Result.ok(null);
    }

    @Operation(summary = "更新全部状态")
    @GetMapping("/auth/allCheckCart/{isChecked}")
    public Result allCheckCart(@PathVariable Integer isChecked){
        cartService.allCheckCart(isChecked);
        return Result.ok(null);
    }

    @Operation(summary = "清空购物车")
    @GetMapping("/auth/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.ok(null);
    }

    @Operation(summary = "选中的购物车")
    @GetMapping("/auth/getAllChecked")
    public List<CartInfo> getAllCkecked(){
        List<CartInfo> cartInfoList=cartService.getAllCkecked();
        return cartInfoList;
    }
}
